#include "CTimerHandler.h"
#include "Types.h"

CTimerHandler::CTimerHandler(unsigned long delay)
: mDelay(delay)
, mLastTime(0)
, mEnabled(false)
{
}

void CTimerHandler::start()
{
   mLastTime = millis();
   mEnabled = true;
}

void CTimerHandler::stop()
{
   mEnabled = false;
}

uint8_t CTimerHandler::processTimer()
{
   uint8_t retVal = TIMER_NOT_FIRED;
   
   if (true == mEnabled)
   {
      if ((millis() - mLastTime) >= mDelay)
      {
         // Required delay passed since last TIMER_FIRED message
         retVal = TIMER_FIRED;
         start();
      }
   }
   
   return retVal;
}